package com.it1997.astar;


public class Node implements Comparable<Node> {
    Point point; // 当前结点坐标
    int g; // 当前结点g值：距离起点的距离
    int h; // 当前结点的h值：记录终点的预估值
    Node parent; // 父级结点，用于反推轨迹

    public Node(Point p, int g, int h, Node parent) {
        this.point = p;
        this.g = g;
        this.h = h;
        this.parent = parent;
    }

    double f() {
        return g + h;
    }


    @Override
    public int compareTo(Node node) {
        if (node == null) {
            return -1;
        }

        if (f() > node.f()) {
            return 1;
        } else if (f() < node.f()) {
            return -1;
        }
        return 0;
    }
}
